package com.hailiang.saas.auth.common;

import com.google.common.collect.Lists;
import com.hailiang.saas.uc.api.vo.UcUserInfoVO;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;

import java.util.Collection;
import java.util.Set;

/**
 * @author : pangfuzhong
 * @description
 * @date : 2021/9/21 11:49
 */
@Data
public class DefaultUserDetails implements UserDetails {
    // 账号token
    private String accessToken;
    // 时间戳,用于token加密
    private Long timestamp;
    // 账号名称
    private String userName;
    // 账号密码
    private String password;
    // 是否是系统注册(如果为1,需要登陆后跳转修改密码页面)
    private Byte accountSource;
    // 本账号对应的唯一用户
    private UcUserInfoVO ucUserInfoVO;
    // 当前用户权限信息
    private Set<String> permissions;
    // 当前用户角色信息
    private Set<String> roles;

    private Boolean isAccountNonExpired;
    private Boolean isAccountNonLocked;
    private Boolean isCredentialsNonExpired;
    private Boolean isEnabled;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Lists.newArrayList();
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.userName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
